package com.hongshan.wallet.core.wallet

import com.hongshan.wallet.BR
import com.hongshan.wallet.MyApplication
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BaseRecyclerAdapter
import com.hongshan.wallet.base.BaseViewHolder
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.BankCardBean

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.wallet
 * @author   : zhangxx
 * @date     : 2019/3/26
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class BankCardRecycleAdapter(var list: List<BankCardBean> = arrayListOf()) : BaseRecyclerAdapter() {

    override fun getViewModel(
        holder: BaseViewHolder<MyViewModel>,
        position: Int
    ): MyViewModel {
        val viewModel = BankCardRecycleViewModel(MyApplication.applicationContext)
        viewModel.background.set(
            when (position % 3) {
                0 -> viewModel.backgroundDraw[0]
                1 -> viewModel.backgroundDraw[1]
                else -> viewModel.backgroundDraw[2]
            }
        )
        if (position != list.size) {
            val bankCard = list[position]

            viewModel.bankName.set(bankCard.bank)
            viewModel.cardNum.set(bankCard.card_no)
            viewModel.cardType.set(bankCard.card_type_name)
            viewModel.cardStatus.set(
                if (bankCard.status ==1) {
                    "已启用"
                } else{
                    "已禁用"
                }
            )
            viewModel.icon.set(bankCard.bank_img)
        }
        return viewModel
    }

    override fun getLayoutIdForPosition(position: Int) =
        if (position == itemCount - 1) R.layout.list_footer_add_bank_card else R.layout.list_item_bank_card

    override fun initVariableId(position: Int) = BR.vm

    override fun getItemCount() = list.size+1
}